***  Estimates fixed effects using the panel of mothers from PSID


set more off
clear

log using "$log_files/1_fixed_effect", replace



clear
*Run the loop for mothers (m) and fathers (f)

foreach gen in m f {
*******************************************************************
*************  A. import PSID data for mothers   *****************
*******************************************************************
*** Read panel data on all mothers (and their spouses) for any children in CDS (observations by mid-year)

clear 
use "$data/MotherPanelCDS.dta"
tab year
rename *, lower
*drop PSID state, keep FIPS 
drop state
rename stfips state


*Drop mothers who do not satisfy
*Age 16-45 or missing at birth of oldest child
*Age 18-65 or missing for fathers and mothers
keep if ind_not_sample==0

********************************************************************************
******************* B. Additional sample restrictions *************************
********************************************************************************

keep if state>=1 & state<=56
keep if `gen'_exper>=0 & `gen'_exper<=50    // only positive potential experience
drop if ln_wage_`gen'==.
drop if num_0_12>0 
*drop if year==2002 | year==2007

tab year



********************************************************************************
**************************** C. FIXED EFFECTS ESTIMATION ***********************
********************************************************************************

* Get predicted log wages as of 0 work experience, no kids, using FE regression (mothers and fathers)


xtset `gen'id year

xtreg ln_wage_`gen'  `gen'_exper `gen'_exper2 i.state ib2002.year, fe   // take out any state averages as well (i.e. assumes state differences are not due to average HC differences)
matrix coeffFE = e(b)
predict ln_wageFE_`gen', u


collapse (mean) ln_wageFE_`gen' ln_wage_`gen' (count) N_FE_`gen' = ln_wageFE_`gen', by(`gen'id)


tab N_FE_`gen'

keep `gen'id ln_wageFE_`gen' N_FE_`gen'

* Save FE data
sort `gen'id 
save "$temp/ln_HC`gen'_dat", replace

}

log close


